package com.wang.ioc.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;

public class ConfigUtils {

	/**
	 * 获取当前应用的包名   
	 * @param context
	 * @return
	 */
	public static String getPackageName(Context context){
		PackageInfo info;  
		String packageName=null;
        try {    
            info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);    
            packageName = info.packageName;    
        } catch (NameNotFoundException e) {    
            e.printStackTrace();    
        } 
        return packageName;
	}
	/**
	 * 获取当前应用的版本名称
	 * @param context
	 * @return
	 */
	public static String getVersionName(Context context){
		PackageInfo info;  
		String versionName=null;
		try {    
			info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);    
			versionName = info.versionName;    
		} catch (NameNotFoundException e) {    
			e.printStackTrace();    
		} 
		return versionName;
	}
	/**
	 * 获取当前应用的版本号
	 * @param context
	 * @return
	 */
	public static int getVerionCode(Context context){
		PackageInfo info;   
		int versionCode=-1; 
		try {    
			info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);    
			versionCode = info.versionCode;    
		} catch (NameNotFoundException e) {    
			e.printStackTrace();    
		} 
		return versionCode;
	}
}
